//
//  FPRegisterViewController.m
//  FilmParadise
//
//  Created by lanou3g on 15/7/23.
//  Copyright (c) 2015年 DLYgroup. All rights reserved.
//

#import "FPRegisterViewController.h"
#import "FPRegisterView.h"
#import "FPSqliteManager.h"
#import "FPUserModel.h"
@interface FPRegisterViewController ()
@property (nonatomic , strong) FPRegisterView *registerView;
@end

@implementation FPRegisterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
   // self.navigationController.navigationBar.translucent = NO;
    [self setView];
    [self addTarget];



}
- (void)setView
{
    self.registerView = [[FPRegisterView alloc]init];
    self.view = _registerView;
    
}
- (void)addTarget
{
    [self.registerView.registerBtn addTarget:self action:@selector(registerAct) forControlEvents:UIControlEventTouchUpInside];
}
- (void)registerAct
{
    if (![self.registerView.userName.text isEqualToString:@""]) {
        if (![self.registerView.userPwd.text isEqualToString:@""])
        {
            NSArray *nameArray = [FPSqliteManager selectAllUserName];
            if ([nameArray containsObject:self.registerView.userName.text])
            {
                [self showAlert:@"用户名重名了"];
            }
            else
            {
                [self showAlert:@"注册成功"];
                [FPUserModel ShareInstance].userName = self.registerView.userName.text;
                [FPUserModel ShareInstance].userPwd = self.registerView.userPwd.text;
                [FPUserModel ShareInstance].userPhone = self.registerView.userPhone.text;
                [FPSqliteManager insertUserModel:[FPUserModel ShareInstance]];
                [self.navigationController popViewControllerAnimated:YES];

            }
        }
        else
        {
            [self showAlert:@"密码不能为空"];
        }
    }
    else
    {
        [self showAlert:@"用户名不能为空"];
    }
    
}
//根据NSTimer来给AlertView定时, 让显示完后消失
- (void)timerFireMethod:(NSTimer*)theTimer//弹出框
{
    UIAlertView *promptAlert = (UIAlertView*)[theTimer userInfo];
    [promptAlert dismissWithClickedButtonIndex:0 animated:NO];
    promptAlert =NULL;

}

//弹出AlertView
- (void)showAlert:(NSString *) _message{//时间
    UIAlertView *promptAlert = [[UIAlertView alloc] initWithTitle:@"提示:" message:_message delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
    
    [NSTimer scheduledTimerWithTimeInterval:1.0f
                                     target:self
                                   selector:@selector(timerFireMethod:)
                                   userInfo:promptAlert
                                    repeats:YES];
    [promptAlert show];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
